//
//  FYFMainViewController.m
//  FYFPhotoBrowser
//
//  Created by fuyoufang on 16/5/14.
//  Copyright © 2016年 深圳－真二网. All rights reserved.
//

#import "FYFMainViewController.h"
#import "FYFMainViewCell.h"
#import "FYFImageInfo.h"
#import "FYFPhotoBrowser.h"

@interface FYFMainViewController () <FYFPhotoBrowserDelegate,FYFImageGroupeViewDelegate>

@property (nonatomic, strong) NSArray *imageInfos;

@end

@implementation FYFMainViewController

#pragma mark - getter
- (NSArray *)imageInfos {
    if (_imageInfos == nil) {
        _imageInfos = [FYFImageInfo imageInfos];
    }
    return _imageInfos;
}

#pragma mark - system

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

#pragma mark - tableView 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FYFMainViewCell *cell = [FYFMainViewCell mainViewCellWithTableView:tableView];
    cell.imageGroupeView.delegate = self;
    cell.imageInfos = self.imageInfos;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}


#pragma mark - FYFImageGroupeViewDelegate <NSObject>

- (void)imageGroupeView:(FYFImageGroupeView *)imageGroupeView
 didTapImageViewAtIndex:(NSInteger)index
              imageView:(UIImageView *)imageView {
    FYFPhotoBrowser *photoBrowser = [[FYFPhotoBrowser alloc] initWithDelegate:self currentIndex:index beginningImageView:imageView];
//    photoBrowser.originImageView = imageView;
    
//    [self.navigationController pushViewController:photoBrowser animated:NO];
    photoBrowser.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self.navigationController presentViewController:photoBrowser animated:NO completion:nil];
}

#pragma mark - FYFPhotoBrowserDelegate

- (NSInteger)numberOfPhotoBrowser:(FYFPhotoBrowser *)photoBrowser {
    return self.imageInfos.count;
}

- (NSString *)photoBrowser:(FYFPhotoBrowser *)photoBrowser thumbnailURLStringAtIndex:(NSInteger)index  {
    FYFImageInfo *imageInfo = self.imageInfos[index];
    return imageInfo.thumbnailURLString;
}

- (NSString *)photoBrowser:(FYFPhotoBrowser *)photoBrowser originalURLStringAtIndex:(NSInteger)index {
    FYFImageInfo *imageInfo = self.imageInfos[index];
    return imageInfo.originalURLString;
}

@end
